import request from '@/api/request';
import { AxiosPromise } from 'axios';
import { NotificationQuery, NotificationVO, UserNotificationSettingsVO } from './types';
import { NOTIFICATION_DETAIL_TYPE } from '@/constants/common/notification-type';

// 获取未读通知列表
export function getUnreadNotifications(): AxiosPromise<NotificationVO[]> {
  return request({
    url: '/api/v1/notifications/unread',
    method: 'get'
  });
}

// 分页获取通知列表
export function getNotificationList(
  params: NotificationQuery
): AxiosPromise<PageResult<NotificationVO[]>> {
  return request({
    url: '/api/v1/notifications/list',
    method: 'get',
    params
  });
}

// 标记单条通知为已读
export function markNotificationAsRead(id: string): AxiosPromise<void> {
  return request({
    url: `/api/v1/notifications/${id}/read`,
    method: 'patch'
  });
}

// 标记所有通知为已读
export function markAllNotificationsAsRead(): AxiosPromise<void> {
  return request({
    url: '/api/v1/notifications/read-all',
    method: 'post'
  });
}

// 获取未读通知数量
export function getUnreadNotificationCount(): AxiosPromise<number> {
  return request({
    url: '/api/v1/notifications/unread-count',
    method: 'get'
  });
}

// 获取用户通知设置
export function getNotificationSettings(): AxiosPromise<UserNotificationSettingsVO> {
  return request({
    url: '/api/v1/notifications/settings',
    method: 'get'
  });
}

// 更新用户通知设置
export function updateNotificationSettings(
  settingsVO: UserNotificationSettingsVO
): AxiosPromise<void> {
  return request({
    url: '/api/v1/notifications/settings',
    method: 'put',
    data: settingsVO
  });
}

// 删除通知
export function deleteNotification(id: string): AxiosPromise<void> {
  return request({
    url: `/api/v1/notifications/${id}`,
    method: 'delete'
  });
}

// 清空所有通知
export function clearAllNotifications(): AxiosPromise<void> {
  return request({
    url: '/api/v1/notifications/clear-all',
    method: 'delete'
  });
}

// 发送类型化通知
export function sendNotificationByType(
  typeCode: NOTIFICATION_DETAIL_TYPE,
  params: Record<string, any>
): AxiosPromise<void> {
  return request({
    url: `/api/v1/notifications/send/${typeCode}`,
    method: 'post',
    data: params
  });
}
